<template>
  <div class="product-list-form">
    <el-form ref="form" label-width="80px">
      <el-form-item label="查询关键字">
        <el-input v-model="form.ikey"></el-input>
      </el-form-item>
      <el-form-item label="最低价格">
        <el-input-number
          :min="0"
          :max="100000"
          v-model="form.minPrice"
        ></el-input-number>
      </el-form-item>
      <el-form-item label="最高价格">
        <el-input-number
          :min="0"
          :max="100000"
          v-model="form.maxPrice"
        ></el-input-number>
      </el-form-item>
      <el-form-item label="起始时间">
        <el-date-picker
          type="datetime"
          placeholder="选择日期"
          style="width: 100%"
          value-format="yyyy-MM-dd HH:mm:sss"
          v-model="form.beginTime"
        ></el-date-picker>

        <el-col class="line" :span="2">-</el-col>

        <el-date-picker
          type="datetime"
          placeholder="选择时间"
          style="width: 100%"
          value-format="yyyy-MM-dd HH:mm:sss"
          v-model="form.endTime"
        ></el-date-picker>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="onSearch">查询</el-button>
        <el-button @click="onClean">清空</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
export default {
  name: "ProductListForm",
  props: {
    ikey: String,
    minPrice: Number,
    maxPrice: Number,
    beginTime: String,
    endTime: String,
  },
  data() {
    return {
      form: { ...this.$props },
    };
  },
  methods: {
    onSearch() {
      for (let i in this.form) {
        this.$emit(`update:${i}`, this.form[i]);
      }
    },
    onClean() {
      this.form = {
        ikey: "",
        minPrice: 0,
        maxPrice: 0,
        beginTime: "",
        endTime: "",
      };
      for (let i in this.form) {
        this.$emit(`update:${i}`, this.form[i]);
      }
    },
  },
};
</script>
